<template>
  <!--分析报表-企业客流查询 -->
  <el-row style="height:100%">
    <page report="true">
      <div class="page-content report-con">
        <reportCompanyHeader></reportCompanyHeader>
        <div class="hei13"></div>
        <reportWeekEcharts :id="'companyEcharts'"></reportWeekEcharts>
        <!--<reportcharts :title="global.title"-->
                      <!--:x_data="xData" :t_color="tColor" :title_text="titleText" :y_name="yName"-->
                      <!--:y_data="yData" ref='echarts' :timeSize='timeSize'-->
        <!--&gt;</reportcharts>-->
        <!--<div class="hei13"></div>-->
        <!--<reporttable :isCase="true" :tableData="table.tableData" :tableHead="table.tableHead"    ref='table' :title="global.title" :kpislist="DataV.kpislist"></reporttable>-->
      </div>
    </page>
  </el-row>
</template>
<style lang="scss">
  .page-content {
    &.report-con {
      padding: 0 0;
    }
    padding: 15px;
    .fr {
      float: right;
    }
    .el-table {
      margin-bottom: 10px;
    }
    .paging {
      margin: 15px;
      height: 28px;
    }
    .hei13 {
      height: 15px;
      width: 100%;
    }
  }
</style>
<script>
  let moment = require("moment");
  import page from "@/components/page/page";
  import reportCompanyHeader from "@/components/analyzeReport/reportpublic/reportCompanyHeader";
  import reportWeekEcharts from "@/components/analyzeReport/reportpublic/reportWeekEcharts";
  import reporttable from "@/components/analyzeReport/reportpublic/reporttable";
  import reportGlobal from "@/components/global/reportGlobal";//公共配置
  let kpiColor = reportGlobal.colorList;
  export default {
    data: function() {
      return {
        DataV:{},      //head条件接收
        tableKpis:[],//
        headData:[],//头部参数
        global:[],//公共参数
      };
    },
    components: {
      page,
      reportWeekEcharts,
      reporttable,
      reportCompanyHeader,
    },
    created() {
      for (let i in reportGlobal.queryList) {
        if (reportGlobal.queryList[i].name == '企业查询报表') {
          this.global = reportGlobal.queryList[i]
        }
      }
      this.$Bus.$emit('Loading',false);
      this.$Bus.$on('UpCondition',(data,isAll)=>{
        console.log(data);
        console.log(isAll);
        this.headData  = data
        if(isAll){
          this.getCompanyTimeDivision()
        }else{

        }
        this.$Bus.$emit('Loading',false);
      })
    },
    mounted() {},
    beforeDestroy() {
      this.$Bus.$off('UpCondition')
    },
    watch:{},
    methods: {
      //获取指标接口
      getKpis(id){
        this.$Bus.$emit('Loading',true);
        let url='/sys/report_assist/get_indicator_list'
        let data = {
          org_id_list : id,
          org_type : this.global.org_type,
        }
        this.$api.post(url,data)
        .then(data=>{
          if(data){
            this.DataV.kpislist = data.data.filter(x=>{
              return this.global.indicator_keys.includes(x.key)
            })
            //根据id对指标进行排序
            this.DataV.kpislist.sort((x,y)=>{
              if(x.id < y.id){
                return -1
              }else{
                return 1
              }
            });
            this.tableKpis=this.DataV.kpislist.map(x=>{
              return x.key
            });
            this.$refs.table.kpisBegin(true);
            this.Updata()
          }
          else{
            this.$Bus.$emit('Loading',false);
          }
        })
        .catch(err=>{
          console.log(err,'企业下无指标');
          this.removedata();
          this.$Bus.$emit('Loading',false);
        })
      },
      //获取企业分时报表
      getCompanyTimeDivision(){
        let url = '/sys/report_range/time_division_report_case_company?company=' + this.headData.company_id +
          '&tags=' + this.global.tags + '&indicator_keys=' + this.global.indicator_keys + '&start_day=' + this.headData.start_day +
          '&end_day=' + this.headData.end_day + '&start_hm=00:00&end_hm=23:59'
        this.$api.get(url)
        .then(data=>{
          console.log(data);
          if(data){
            let _data = data.data
            let sum_list = _data.sum_list;//合计列表
            let item_list = _data.item_list;//分时列表
            let xData = [];

            for(let i in sum_list){
              xData.push(sum_list[i].time_tag)
              for(let j in this.DataV.kpislist){
                // sum_list[i][]
              }
            }
            let obj = {}
            obj.x_data = xData
            obj.data = xData
            obj.title = this.global.title
            obj.kpiName = xData
          }
        })
      }
    }
  };
</script>
